<?php
namespace Home\Service;

/*use Cli\Service\CustomerCountServiceModel;*/
/*use Home\Model\DailyDataModel;*/
/*use Home\Model\GroupCustomerStatisticsModel;
use Home\Model\UserCustomerStatisticsModel;
use Common\Lib\GetWeek;
use Common\Lib\GetMonth;*/

class RecruitChannelsGather {

    private $start =   '';
    private $end   =   '';
    private $order = 'id asc';

    private $today = '';


    public function __construct(){
        $this->today = Date('Y-m-d');
    }



    private function getFields(){
        return array('wb_interviewer_num',  'ganji_interviewer_num', 'zhilian_interviewer_num', 'qiancheng_interviewer_num', 'jljh_interviewer_num', 'boss_interviewer_num', 'campus_interviewer_num', 'introduce_interviewer_num', 'other_interviewer_num', 'interviewer_total', 'wb_entry_num', 'ganji_entry_num', 'zhilian_entry_num', 'qiancheng_entry_num', 'jljh_entry_num', 'boss_entry_num', 'campus_entry_num', 'introduce_entry_num', 'other_entry_num', 'entry_total');
    }


    private function getSqlFields(){
        $field = $this->getFields();
        $arr = array();
        foreach ($field as $key => $value) {
            $arr[] = "sum(`". $value . "`) as ".$value;
        }
        return implode(",", $arr);
    }
    public function reSort($re){
        $columen = array_column($re, $this->field);
        array_multisort($columen, $this->sort , SORT_NUMERIC, $re);
        return $re;
    }

    public function getDepartment($start,$end,$department_id,$role_id,$sort_field,$sort_order){
        $this->start =$start;
        $this->end = $end;
         $department_id = $department_id;
        $role_id = $role_id;
        switch($role_id){
            case 16:
              $list  = M('recruit_channels')->field($this->getSqlFields().", department_id as id, department_name as name")
                                                            ->where(array('date'=> array(array('EGT',$this->start),array('ELT',$this->end)),'department_id'=>$department_id))
                                                            ->order($sort_field.' '.$sort_order)
                                                            ->select(); 
            break;
            default :
              $list  = M('recruit_channels')->field($this->getSqlFields().", department_id as id, department_name as name")
                                                            ->where(array('date'=> array(array('EGT',$this->start),array('ELT',$this->end))))
                                                            ->group('department_id')
                                                            ->order($sort_field.' '.$sort_order)
                                                            ->select();
              
        }                                                                                  
        return $this->reSort($list);
    }




    
}